<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<style>
    li{
        list-style: none;
        float: left;
        padding: 20px 15px;
        cursor: pointer;
    }
    .tab {
        width: 900px;
        height: 60px;
        margin: 300px auto;
    }
    .tab_list {
        width: 100%;
        height: 56.3px;
        border-bottom: 1px solid #999;
        line-height: 1;
    }
    ul{
        margin-left: -40px;
    }
    .active{
        background: salmon;
        color: white;
    }
    .item {
        display: none;
    }
</style>
<body>
    <div class="tab">
        <div class="tab_list">
            <ul>
                <li class="active">商品介绍</li>
                <li>规格与包装</li>
                <li>售后保障</li>
                <li>商品评论（99999+）</li>
                <li>手机社区</li>
            </ul>
        </div>
        <div class="tab_con">
            <div class="item" style="display: block">
                商品介绍内容
            </div>
            <div class="item">
                规格与包装内容
            </div>
            <div class="item">
                售后保障内容
            </div>
            <div class="item">
                商品评论内容
            </div>
            <div class="item">
                手机社区内容
            </div>
        </div>
    </div>
    <script>
        var tab_list = document.querySelector('.tab_list');
        var lit = tab_list.querySelectorAll('li');
        var items = document.querySelectorAll('item');
        for (var i = 0;i < lit.length;i++) {
            lit[i].setAttribute('index',i);
            lit[i].onclick = function () {
                //先清除所有的li 然后再给点击的li加上样式
                for (var i = 0;i < lit.length;i++){
                    lit[i].className = '';
                }
                this.className = 'active';
                var index = this.getAttribute('index');
                console.log(index);
                for (var o = 0;i< items.length;i++){
                    items[i].style.display = 'none';
                }
                items[index].style.display = 'block';
            }
        }
    </script>
</body>
</html>